﻿<cfscript>
/** 
* ORM InstituteAdmin
* 
* @hint "Hibernate persistenter t_institute_admin. 院系(部)管理团队" 
* 
*/ 

component 
	displayname="public.service.orm.senate.InstituteAdmin" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="InstituteAdmin" 
	table="t_institute_admin"
	{

	property type="string" name="AuthID" column="auth_id" fieldtype="id" generator="assigned" hint="授权序列";

	property type="string" name="GroupID" column="group_id" hint="用户组";

	property name="Institute" fieldtype="many-to-one" fkcolumn="institute_id" cfc="Institute"  hint="院系所号";
	property name="Teacher" fieldtype="many-to-one" fkcolumn="tch_id" cfc="Teacher"  hint="教师职工号";

	/**
	* @hint "自定义主键规则"
	* 
	* @InstituteID "院系所号"
	*/
	public string function getNextID( required string InstituteID ) output=false {
		
		var nextID = arguments.InstituteID & numberFormat(1, "0__");
		var checkArray = ORMExecuteQuery("select AuthID from InstituteAdmin 
											where AuthID like :condition 
											order by AuthID desc", {condition = arguments.InstituteID & "___"}, { maxResults=1 });

		/* 
			主键生成规则 
			
			学院代码 + 3位为流水号
			
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = arguments.InstituteID & numberFormat((right(checkArray[1], 3) + 1), "0__");
			
		}

		return nextID;

	}
	
}

</cfscript>